package com.rgs.se.zookeeper.zkclient;

import org.I0Itec.zkclient.ZkClient;

/**
 * @author Ren Gaoshuai
 * @ClassName TestMain
 * @Description 方式二 zkclient
 * @date 2021-10-27 9:28
 **/
public class TestMain {

    /**
     * 引入依赖
     *         <dependency>
     *             <groupId>com.101tec</groupId>
     *             <artifactId>zkclient</artifactId>
     *             <version>0.10</version>
     *         </dependency>
     *  对原生api进行了简单封装
     */

    private static final String CONNECTION = "127.0.0.1:2181";
    private static final int SESSION_OUTTIME = 10000;

    public static void main(String[] args) {
        ZkClient client = new ZkClient(CONNECTION, SESSION_OUTTIME);

        //create  delete
        //临时节点
        client.createEphemeral("/aaa");
        //级联创建节点
        client.createPersistent("/aaa/a2","a2内容");
        //递归删除
        client.deleteRecursive("/aaa");
        //更新
        client.writeData("/aaa","新内容");
        //是否存在
        client.exists("/aaa");
        //读取节点的数据
        client.readData("/aaa");
    }
}
